package com.dawson.gitosc.adapter;

import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017/1/5.
 */

public class ViewPagerAdater extends PagerAdapter {
    private List<View> viewList;

    public ViewPagerAdater() {
        viewList = new ArrayList<>();
    }

    @Override
    public int getCount() {
        return this.viewList.size();
    }

    @Override
    public Object instantiateItem(ViewGroup collection, int position) {
        View view = viewList.get(position);
        collection.addView(view);
        return view;
    }

    @Override
    public void destroyItem(ViewGroup collection, int position, Object view) {
        collection.removeView((View) view);
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == object;
    }

    public void setData(List<View> viewList){
        if(viewList == null){
            this.viewList.clear();
        }else {
            this.viewList.addAll(viewList);
        }
        notifyDataSetChanged();//通知数据更新
    }
    public  List<View>  getData(){
        if (this.viewList == null) {
            this.viewList = new ArrayList<>();
        }

        return this.viewList;
    }
}
